package com.itheima.demo06;

public class Cook extends Thread{
    //厨师的线程

    @Override
    public void run() {
        /*
         * 1.循环
         * 2.同步代码块
         * 3.判断是否结束（结束）
         * 4.判断是否结束（不结束，执行代码）
         *
         */
        while (true){
            synchronized (Desk.lock){
                if (Desk.count == 0){
                    break;
                }else {
                    if (Desk.flag == 1){
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }else {
                        System.out.println("厨师在做面条");
                        Desk.flag = 1;
                        Desk.lock.notifyAll();
                    }
                }
            }
        }
    }
}
